package com.githan.bootsecurity.config;

import com.githan.bootsecurity.response.Result;
import com.githan.bootsecurity.response.ResultCode;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * @author https://github.com/Han56
 * @date 2021/4/11 19:36
 * 账户被挤下线处理器
 */
@Component
public class MyExpiredSessionStrategy extends JSONAuthentication implements SessionInformationExpiredStrategy {
    /**
     * 当账户被踢下线的时候如何处理
     */
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        Result result=Result.error(ResultCode.USER_ACCOUNT_USE_BY_OTHERS);
        this.WriteJSON(sessionInformationExpiredEvent.getRequest(),sessionInformationExpiredEvent.getResponse(),result);
    }


}
